package com.mac.intellect_flow.admin.controller.flowable;

import com.mac.intellect_flow.flowable.service.SysDeployFormService;
import com.mac.intellect_flow.flowable.service.SysFormService;
import com.mac.intellect_flow.reply.PageParam;
import com.mac.intellect_flow.reply.PageResult;
import com.mac.intellect_flow.reply.R;
import com.mac.intellect_flow.sys.entity.SysDeployForm;
import com.mac.intellect_flow.sys.entity.SysForm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程表单管理
 *
 * @author mac
 */
@Slf4j
@Tag(name = "流程表单管理")
@RestController
@RequestMapping("/flowable/form")
public class SysFormController {
    @Autowired
    private SysFormService sysFormService;

    @Autowired
    private SysDeployFormService sysDeployFormService;

    /**
     * 查询流程表单分页
     */
    @Operation(summary = "查询流程表单分页")
    @PreAuthorize("@ps.hasPermi('flowable:form:list')")
    @GetMapping("/list")
    public R<PageResult<SysForm>> list(SysForm sysForm, PageParam pageParam) {
        return R.success(sysFormService.queryPage(sysForm,pageParam));
    }

    @Operation(summary = "由条件查询流程表单")
    @GetMapping("/formList")
    public R formList(SysForm sysForm) {
        List<SysForm> list = sysFormService.selectSysFormList(sysForm);
        return R.success(list);
    }
    /**
     * 导出流程表单列表
     */
  /*  @PreAuthorize("@ps.hasPermi('flowable:form:export')")
    @GetMapping("/export")
    public R export(SysForm sysForm) {
        List<SysForm> list = sysFormService.selectSysFormList(sysForm);
        ExcelUtil<SysForm> util = new ExcelUtil<SysForm>(SysForm.class);
        return util.exportExcel(list, "form");
    }*/

    /**
     * 获取流程表单详细信息
     */
    @Operation(summary = "获取流程表单详细信息")
    @PreAuthorize("@ps.hasPermi('flowable:form:query')")
    @GetMapping(value = "/{formId}")
    public R getInfo(@Parameter(name = "流程表单ID") @PathVariable("formId") Long formId) {
        return R.success(sysFormService.selectSysFormById(formId));
    }

    /**
     * 新增流程表单
     */
    @Operation(summary = "新增流程表单")
    @PreAuthorize("@ps.hasPermi('flowable:form:add')")
    @PostMapping
    public R add(@RequestBody SysForm sysForm) {
        return R.success(sysFormService.insertSysForm(sysForm));
    }

    /**
     * 修改流程表单
     */
    @Operation(summary = "修改流程表单")
    @PreAuthorize("@ps.hasPermi('flowable:form:edit')")
    @PutMapping
    public R edit(@RequestBody SysForm sysForm) {
        return R.success(sysFormService.updateSysForm(sysForm));
    }

    /**
     * 删除流程表单
     */
    @Operation(summary = "删除流程表单")
    @PreAuthorize("@ps.hasPermi('flowable:form:remove')")
    @DeleteMapping("/{formIds}")
    public R remove(@PathVariable Long[] formIds) {
        return R.success(sysFormService.deleteSysFormByIds(formIds));
    }


    /**
     * 挂载流程表单
     */
    @Operation(summary = "挂载流程表单")
    @PostMapping("/addDeployForm")
    public R addDeployForm(@RequestBody SysDeployForm sysDeployForm) {
        return R.success(sysDeployFormService.insertSysDeployForm(sysDeployForm));
    }
}
